#include"DirectXFramework.h"

void CDirectXFramework::Update(float deltaTime)
{
	static int timer = 0;
	m_PickThis = NONE;
	UpdateKeyboard();

	switch(m_GameState)
	{
	case MENU:
		{
			//check index and fix menu 
			//according to index position
			updateIndex();

			//updates picking in MENU state
			updateMenuPicking(timer);

			if(Player1->IsConnected())
			{
				//calls function to look for controller input
				updateMenuContoller();
			}


			///GARY TEST CODE TO SHOW FMOD WORKS PRESS "I" WHILE IN MENU
			//WILL ERASE AFTER PEOPLE SEE HOW IT WORKS
			if(checkKeyHits(DIK_I))
			{
				m_soundEng.result = m_soundEng.system->playSound(FMOD_CHANNEL_FREE, m_soundEng.sound[3], false, &m_soundEng.channel[3]);
				ERRCHECK(m_soundEng.result);
			}



		}
		break;
	case RULES:
		{
			
			//change to menu via keyboard
			if(checkKeyHits(DIK_B))
			{
				m_GameState = MENU;
			}
			//change to control screen via keyboard
			if(checkKeyHits(DIK_C))
			{
				m_GameState = CONTROL;
			}



			//change back to menu via controller
			if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
			{
				if(m_lastButtonState != Player1->GetState().Gamepad.wButtons )
				{
					m_GameState = MENU;
				}
			}

			//change to control screen via controller
			if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
			{
				if(m_lastButtonState != Player1->GetState().Gamepad.wButtons )
				{
					m_GameState = CONTROL;
				}
			}

	

		}
		break;
	case CONTROL:
		{
			//change to rules via keyboard
			if(checkKeyHits(DIK_B))
			{
				m_GameState = RULES;
			}

			//change to control screen via controller
			if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
			{
				if(m_lastButtonState != Player1->GetState().Gamepad.wButtons )
				{
					m_GameState = RULES;
				}
			}

		}
		break;
	case CREDITS:
		{
			//updateCredits();
			if(checkKeyHits(DIK_B))
			{
				m_GameState = MENU;
			}

			if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
			{
				if(m_lastButtonState != Player1->GetState().Gamepad.wButtons )
				{
					m_GameState = MENU;
				}
			}
		}
		break;
	case PLAY:
		{
			//this keeps camera from being moved while in map mode
			//if map is hidden then these camera move functions will run
			if(m_MapState == HIDDEN)
			{
				//updates camera movement via gamepad
				updateGamePadCamMove(deltaTime);

				//updates camera movement via keyboard
				updateKeyCamMove(deltaTime);
			}

			if(Player1->IsConnected())
			{
				//this updates the movement of the mouse arrow
				//based on the controller input
				updateArrowByControl();
				//updates the controller events(buttons)
				updatePlayGamePadEvents();
			}

			//updates PLAY state key events
			//e.g. reset cards, hide hand, show map
			updatePlayKeyEvents();

			//updates picking in Play state
			updatePlayPicking(deltaTime);

			if(m_PlayerHasWon == 1)
			{
				::PostQuitMessage(0);
			}

		}
		break;
	case WIN:
		if(checkKeyHits(DIK_RETURN))
		{
			m_GameState = MENU;
		}
		break;
	default:
		break;	
	}
	//gets the state value to compare next time
	m_lastButtonState = Player1->GetState().Gamepad.wButtons;
}